# @Version:1.0
# @Author：green-citrus

# str_a = "reg-green"
# print(id(str_a))
#
# # 不能修改字符串的某个元素
# # str_a[2] = "李"
#
# # 可以修改指向
# str_a = "abc"
# print(id(str_a))

# for e in str_a:
#     print(e)
#
# index = 0
# while index < len(str_a):
#     print(str_a[index])
#     index += 1

# str_names = "jack tom mary hsp nono tom"
# # (1)str.replace(old,new,[count])
# # 返回字符串的副本，其中出现的所有子字符串old都将被替换为new
# # 如果给出了可选参数count，则只替换前count次出现
# str_names_new = str_names.replace("jack", "杰克", 1) # 将"jack"替换成“杰克"，只替换一个
# print(str_names)
# print(str_names_new)

# str_names = "jack tom mary hsp nono tom"
# # (2)split(sep=None, max-split=-1)
# # 返回一个由字符串内单词组成的列表，使用sep作为分隔字符串
# # 如果给出了max-split，则最多进行max-split次拆分
# # 如果max-split未指定或为-1，则不限制拆分次数进行所有可能的拆分
# str_names_split = str_names.split(" ") # 对字符串使用空格进行分割
# print(str_names_split)

# str_names = "jack tom mary hsp nono tom"
# #            012345
# print(str_names.count("tom")) # 2
# print(str_names.index("tom")) # 5

# （3）strip([chars])
# 如果原字符串中前导和末尾字符和chars里面的某个字符相等，就去除
# 原字符串不变，返回新串
# str_names = "****jack tom mary hsp nono tom****"
# print(str_names.strip("*")) # jack tom mary hsp nono tom
# print("12223haha2132".strip("123")) # haha

# str_name = "AAA_yy"
# print(str_name.lower()) # AAA_YY
# print(str_name.upper()) # aaa_yy

# print(ord("h")) # 104
# print(chr(104)) # h

# 1、定义一个字符串, str_names = "tom jack mary nono smith hsp"
str_names = "tom jack mary nono smith hsp"

# 需求1：－统计一共有多少个人名
str_names_list = str_names.split(" ");
print(len(str_names_list)) # 6

# 需求2：－如果有"hsp"则替换成"老韩""
str_names = str_names.replace("hsp", "老韩")
print(str_names)

# 需求3：－如果人名是英文，则把首字母改成大写
# 思路：
#   1.定义新字符串保存新结果
#   2.遍历列表，如果发现是英文名，就将其首字母改成大写str.capitalize
#   3.拼接到str_names_upper即可
str_names_upper = ""
for e in str_names_list:
    if e.isalpha():
        e.capitalize()
    str_names_upper += e + " "
# 去掉首尾的空格
str_names_upper = str_names_upper.strip(" ")
print(str_names_upper)


